@extends('layout.default')

@section('stylesheet')
  <link href="//cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
@stop

@section('layout.content')

  <div class="row">
    <div class="col-xs-12">
      <h4 class="header blue">{{$grade->plan->name}}>{{$grade->category->name}}</h4>
    </div>
  </div>

  <div class="row">
    <div class="col-xs-12">
      <form class="form-horizontal" id="staff-create" autocomplete="off">
        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right"> 教学计划： </label>
          <label class="col-sm-8 control-label align-left">
            <b>{{$grade->plan->name}}</b>
          </label>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right"> <b><span
                  class="red">*</span> {!!$grade->plan->present()->categoryTitle!!}类别：</b> </label>
          <div class="col-sm-3">
            <select name="cid" class="form-control cid">
              <option>请选择</option>
              @foreach($grade->plan->categories as $cate)
                <option value="{{$cate->id}}" {{$grade->category->id==$cate->id?'selected':''}}>{{$cate->name}}</option>
              @endforeach
            </select>

          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right" for="name"> <b><span
                  class="red">*</span> {!!$grade->plan->present()->categoryTitle!!}名称：</b> </label>
          <div class="col-sm-6">
            <input type="text" class="form-control" value="{{$grade->name}}" name="name"/>
            <input type="hidden" name="pid" value="{{$grade->plan->id}}"/>
            <input type="hidden" name="cid" value="{{$grade->category->id}}"/>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right" for="number"> <b><span class="red">*</span> 招生人数：</b>
          </label>
          <div class="col-sm-2">
            <input type="text" class="form-control" value="{{$grade->number}}" name="number" placeholder="招生人数"/>
          </div>
          <div class="col-sm-4">
            <div class="radio">
              <label class="inline no-padding-left">
                <input name="limit" type="checkbox" value="1"
                       class="ace ace-checkbox-2" {{$grade->limited==1?'checked':''}}>
                <span class="lbl"> <b>额满限招</b></span>
              </label>
              <label class="inline">
                <input name="exam" type="checkbox" value="1"
                       class="ace ace-checkbox-2" {{$grade->exam==1?'checked':''}}>
                <span class="lbl"> 入学考试</span>
              </label>
              <label class="inline">
                <input name="opus" type="checkbox" value="1"
                       class="ace ace-checkbox-2" {{$grade->opus==1?'checked':''}}>
                <span class="lbl"> 上交作品</span>
              </label>
            </div>
          </div>
        </div>

        <div class="form-group exam {{$grade->exam==0?'operate':''}}">
          <label class="col-sm-3 control-label no-padding-right" for="content"> <b><span class="red">*</span> 考试内容：</b>
          </label>
          <div class="col-sm-6">
            <textarea rows="4" class="form-control" name="content" id="content"
                      placeholder="考试内容及条件">{{$grade->content}}</textarea>
          </div>
        </div>
        <div class="form-group exam {{$grade->exam==0?'operate':''}}">
          <label class="col-sm-3 control-label no-padding-right" for="exam_date"> <b><span class="red">*</span>
              考试时间：</b> </label>
          <div class="col-sm-2">
            <input class="form-control" type="text"
                   value="{{!empty($grade->exam_date)?date('Y-m-d',$grade->exam_date):''}}" name="exam_date"
                   placeholder="考试日期"/>
          </div>
          <div class="col-sm-2">
            <input class="form-control" type="text"
                   value="{{!empty($grade->exam_begin)?date('H:i',strtotime($grade->exam_begin)):''}}" name="exam_begin"
                   placeholder="考试开始时间"/>
          </div>
          <div class="col-sm-2">
            <input class="form-control" type="text"
                   value="{{!empty($grade->exam_end)?date('H:i',strtotime($grade->exam_end)):''}}" name="exam_end"
                   placeholder="考试结束时间"/>
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right" for="common"> 类型：</label>
          <div class="col-sm-3">
            <div class="radio">
              <label class="inline no-padding-left">
                <input name="common" type="checkbox" value="1"
                       class="ace ace-checkbox-2" {{$grade->common==1?'checked':''}}>
                <span class="lbl"> 常规课程</span>
              </label>
            </div>
          </div>
        </div>
        <div class="form-group study-time {{$grade->common==0?'showorhide':''}}">
          <label class="col-sm-3 control-label no-padding-right" for="week"> <b><span class="red">*</span> 上课时间：</b>
          </label>
          <div class="col-sm-3">
            <div class="radio">
              <label class="inline no-padding-left">
                <input name="week" type="checkbox" value="6"
                       class="ace ace-checkbox-2" {{$grade->week==6?'checked':''}}>
                <span class="lbl"> 星期六</span>
              </label>
              <label class="inline">
                <input name="week" type="checkbox" value="7"
                       class="ace ace-checkbox-2" {{$grade->week==7?'checked':''}}>
                <span class="lbl"> 星期天</span>
              </label>
            </div>
          </div>
        </div>

        <div class="form-group study-date {{$grade->common==1?'showorhide':''}}">
          <label class="col-sm-3 control-label no-padding-right" for="week"> <b><span class="red">*</span> 上课时间：</b>
          </label>
          <div class="col-sm-3">
            <input class="form-control" type="text" name="study_date" placeholder="上课日期"
                   value="{{!empty($grade->study_date)?date('Y-m-d',$grade->study_date):''}}"/>
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right"> </label>
          <div class="col-sm-2">
            <input class="form-control" type="text" value="{{date('H:i',strtotime($grade->grade_begin))}}"
                   name="grade_begin" placeholder="上课开始时间"/>
          </div>
          <div class="col-sm-2">
            <input class="form-control" type="text" value="{{date('H:i',strtotime($grade->grade_end))}}"
                   name="grade_end" placeholder="上课结束时间"/>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right" for="classroom"> 培训教室：</label>
          <div class="col-sm-2">
            <input type="text" class="form-control" value="{{$grade->classroom}}" name="classroom" placeholder="培训教室"/>
          </div>
          <label class="col-sm-1 control-label no-padding-right" for="teacher"> 老师：</label>
          <div class="col-sm-2">
            <input type="text" class="form-control" value="{{$grade->teacher}}" name="teacher" placeholder="培训老师"/>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right" for="exam"> 备注 </label>
          <div class="col-sm-6">
            <textarea rows="8" class="form-control" name="desc" id="desc" placeholder="备注">{{$grade->desc}}</textarea>
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-3 control-label no-padding-right"> </label>
          <div class="col-sm-4">
            <button type="button" class="btn btn-primary submit">
              <i class="ace-icon fa fa-check"></i>
              <span class="">确定</span>
            </button>
          </div>
        </div>

      </form>
    </div>
  </div>

@stop

@section('javascript')
  <script src="//cdn.bootcss.com/moment.js/2.24.0/moment.min.js"></script>
  <script src="//cdn.bootcss.com/moment.js/2.24.0/locale/zh-cn.js"></script>
  <script src="//cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

  <script type="text/javascript">
      $(function () {

          $("input[name='exam']").on('click', function (e) {
              if ($('.exam').is(':hidden')) {
                  $('.exam').show();
              } else {
                  $('.exam').hide();
              }
          });

          $("input[name='common']").on('click', function (e) {
              if ($('.study-date').is(':hidden')) {
                  $('.study-date').show();
                  $('.study-time').hide();
              } else {
                  $('.study-date').hide();
                  $('.study-time').show();
              }
          });

          $("input:checkbox[name='week']").on('click', function (e) {
              $("input:checkbox[name='week']").not(this).attr("checked", false);
          });

          $('.submit').on('click', function () {

              var uri = '{{route('education.grade.update',array($method,$grade->id))}}';

              $.post(uri, {
                  '_token': $("input[name='_token']").attr('value'),
                  '_method': 'put',
                  'name': $("input[name='name']").val(),
                  'pid': $("input[name='pid']").val(),
                  'cid': $(".cid").val(),
                  'number': $("input[name='number']").val(),
                  'limit': $("input[name='limit']:checked").val(),
                  'common': $("input[name='common']:checked").val(),
                  'opus': $("input[name='opus']:checked").val(),
                  'study_date': $("input[name='study_date']").val(),
                  'exam': $("input[name='exam']:checked").val(),
                  'content': $("#content").val(),
                  'exam_date': $("input[name='exam_date']").val(),
                  'exam_begin': $("input[name='exam_begin']").val(),
                  'exam_end': $("input[name='exam_end']").val(),
                  'week': $("input[name='week']:checked").val(),
                  'grade_begin': $("input[name='grade_begin']").val(),
                  'grade_end': $("input[name='grade_end']").val(),
                  'classroom': $("input[name='classroom']").val(),
                  'teacher': $("input[name='teacher']").val(),
                  'desc': $("#desc").val(),
                  'is_submit': true
              }, function (data) {
                  layer.msg(data.message, {time: 1000, shift: -1}, function () {
                      if (data.status === true && data.url != null) {
                          $(window).attr('location', data.url);
                      }
                  });

              }, 'json').error(function (data) {
                  layer.msg(data.responseJSON.message);
              });

          });


          $("input[name='study_date']").datetimepicker({
              format: 'YYYY-MM-DD'
          });

          $("input[name='exam_date']").datetimepicker({
              format: 'YYYY-MM-DD'
          });

          $("input[name='exam_begin']").datetimepicker({
              format: 'HH:mm'
          });

          $("input[name='exam_end']").datetimepicker({
              format: 'HH:mm'
          });

          $("input[name='grade_begin']").datetimepicker({
              format: 'HH:mm'
          });

          $("input[name='grade_end']").datetimepicker({
              format: 'HH:mm'
          });


      });
  </script>
@stop